//
//  VisitorTableViewController.swift
//  Weibo
//
//  Created by 伍银荣 on 2021/12/15.
//  Copyright © 2021 com.WYR. All rights reserved.
//

import UIKit

class VisitorTableViewController: UITableViewController {
    
    //用户登录标记
    private var userLogon = false
    
    var visitorView: VisitorView?
    
    override func loadView() {
        //根据用户的登录情况,决定显示的根视图
        userLogon ? super.loadView() : setupVisitorView()  //三目运算
    }

   
    ///设置访客视图
    private func setupVisitorView() {
        //替换根视图
        visitorView = VisitorView()
        visitorView?.registBtn.addTarget(self, action: #selector(registBtnClicked), for: .touchUpInside)
        visitorView?.loginBtn.addTarget(self, action: #selector(loginBtnClicked), for: .touchUpInside)
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .plain, target: self, action: #selector(registBtnClicked))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .plain, target: self, action: #selector(loginBtnClicked))
        view = visitorView
    }
    

}

extension VisitorTableViewController {
    @objc func registBtnClicked() {
        print("注册")
    }
    
    @objc func loginBtnClicked() {
        print("登录")
    }
}
